package com.habdqn.easybuy.web.front.product;

import com.habdqn.easybuy.entity.Product;
import com.habdqn.easybuy.entity.ProductCategory;
import com.habdqn.easybuy.service.ProductCategoryService;
import com.habdqn.easybuy.service.ProductService;
import com.habdqn.easybuy.service.impl.ProductCategoryServiceImpl;
import com.habdqn.easybuy.service.impl.ProductServiceImpl;
import com.habdqn.easybuy.util.Page;
import com.habdqn.easybuy.util.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Xing.Jiejian
 * @date 2020/12/1
 */
@WebServlet(name = "ProductServlet",urlPatterns = "/product")
public class ProductServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ProductService productService = new ProductServiceImpl();
        String strId = request.getParameter("id");
        if (StringUtils.isNotBlank(strId)){
            Product product = productService.queryById(Integer.parseInt(strId),true);
            request.setAttribute("product",product);
            request.getRequestDispatcher("/WEB-INF/front/product-view.jsp").forward(request,response);
            return;
        }
        response.sendRedirect(request.getContextPath()+"/product/list");
    }
}
